﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Xml.Serialization;

namespace FastUtil.Base
{
    public class CopyUtil:BaseUtil
    {
        public static T CopyEntity<T>(T obj)
        {
            object retval;
            using (MemoryStream ms = new MemoryStream())
            {
                XmlSerializer xml = new XmlSerializer(typeof(T));
                xml.Serialize(ms, obj);
                ms.Seek(0, SeekOrigin.Begin);
                retval = xml.Deserialize(ms);
                ms.Close();
            }
            return (T)retval;
        }
        public static List<T> CopyList<T>(List<T> List)
        {
            List<T> CopyList = new List<T>();
            foreach (T item in List)
            {
                CopyList.Add(CopyEntity(item));
            }
            return CopyList;
        }
    }
}
